#ifndef TEXTVOICEREADERUI_H
#define TEXTVOICEREADERUI_H

#include <QtGui>
#include <QtCore>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QtWidgets>
#endif
#include "TextSpeak.h"
#include "VoicePlayer.h"
#include "FindTextDialog.h"
#include "AudioFile.h"
#include "GenerateAudioFile.h"
#include "LanAudioServer.h"

namespace Ui {
class TextVoiceReaderUI1;
class TextVoiceReaderUI2;
}

class TextVoiceReaderUI : public QMainWindow
{
    Q_OBJECT
public:
    explicit TextVoiceReaderUI(QWidget *parent = nullptr);
    ~TextVoiceReaderUI();

Q_SIGNALS:
    void doBreakLastFindWindow();
    void doBreakGenerateWav();

private Q_SLOTS:
    void on_actionOpenFile_triggered();
    void on_comboBox_currentIndexChanged(const QString &arg1);
    void on_spinBox_valueChanged(int arg1);
    void on_btnPlay_toggled(bool checked);
    void on_actionFind_triggered();
    void on_actionSave_triggered();
    void on_spbVolume_valueChanged(int arg1);
    void on_actionSaveAudio_triggered();
    void on_btnStopGenerate_clicked();
    void on_actionExit_triggered();
    void on_actionChinese_triggered(bool checked);
    void on_actionEnglish_triggered(bool checked);
    void on_btnClose_clicked();
    void on_btnMin_clicked();
    void on_btnMaxNormal_toggled(bool checked);
    void on_actionWindows_Default_triggered();
    void on_actionBlue_Style_triggered();
    void on_actionStartServer_triggered(bool checked);
    void on_actionAbout_Qt_triggered();
    void on_actionAbout_TVR_triggered();

private Q_SLOTS:
    void onExitApp();
    void onChangeEncoding();
    void onSelectTextToSpeak();
    void onTrayReason(QSystemTrayIcon::ActivationReason reason);
    void onPlayToggled();
    void onShowFindDialog();
    void onSpeakProcess(int index);
    void onStartRequest();


protected:
    void closeEvent(QCloseEvent *e);
    void resizeEvent(QResizeEvent *e);
    bool eventFilter(QObject *obj, QEvent *e);

private:
    void selectTextToSpeak();
    void openFile(const QString &fileName, QTextCodec *codecDefault = nullptr);

private:
    Ui::TextVoiceReaderUI1 *ui;
    Ui::TextVoiceReaderUI2 *ui2;

    QTranslator *translator_;
    QSystemTrayIcon trayIcon_;

    QString currrentFileName_;
    QSettings settings_;
    TextSpeak textSpeak_;
    VoicePlayer voicePlayer_;
    QSharedPointer<LanAudioServer> lanAudioServer_;

    //同步滚动文本
    int lastLine_;
    int lastLineHeight_;

    QAction *actionPlay_;
    QAction *actionExit_;

    QString content_;
};

#endif // TEXTVOICEREADERUI_H
